<?php 
  
  require_once 'lib/HTML/Util.php';
  require_once 'lib/HTML/LinkLoader.php';
  require_once 'lib/HTML/FormElements.php';
  /*
  $artist = "'test ' artist' De'sir'é òà \"é\" è";
  $url = "http://testsite.org/test%20mp3_.mp3";
  $title = "test \"TITLE\\\" with 'apostrophes '";
  $release = "NULL";
  $track_mb_id = '6bf1a7c5-5e42-4dc2-8841-3bee9ffk33gr';
  $artist_mb_id = '6bf1a7c5-5e42-4dc2-8841-3bee982233gr';
  $mb_rel_id = '6bfca7c5-5e42-4dc2-8841-3bee9822334b';
  $article = "<b>my</b> \"message\" to the world!!<script type=\"text/javascript\" src=\"js\"></script>";
  $_POST = array(
            title=>$title,
            artist=>$artist,
            url=>$url,
            time_added=>'NOW()',
            release=> $release,
            mb_rel_id=>$mb_rel_id,
            mb_artist_id=>$artist_mb_id,
            article=>$article,
            mb_id=>$track_mb_id,
            op=>'add'
            
        );
  */
  if($_POST[op]=='add'){
  	
    require_once 'controllers/Track.php';
    
    unset($_POST['op']);
    
    $track = new Track($_POST);
    try{ $track->add()->send(); }
    catch(MTException $e){
      if($e->getMessage() == 'INPUT ERROR')
        Proxy::send('<proxy id="response"><errorFields>'.$track->getInputErrors().'</errorFields></proxy>');
      else
        Proxy::send('<proxy id="response"><error>'.$e->getMessage().'</error></proxy>');   
    }
    
    exit();
  }
 
  $ll = new LinkLoader();

  $ll->loadJs(array('Ajax.js','WebServices/WebService.js',
                    'WebServices/MusicBrainz.js','Components/Track.js',
                    'Components/Article.js','MusicTalk.js'));
  $ll->loadJs('js.js','views/track/add/');
  $ll->loadCSS('form.css');
    
  $smarty->assign("title", "Add a Song");
  $smarty->assign_by_ref("ll", $ll);
  $smarty->assign_by_ref("html",new Util());
  $smarty->assign_by_ref("fe",new FormElements());
  
  $smarty->display("head.tpl");
  $smarty->display("nav.tpl");
  // main content
  $smarty->display("../track/add/view.tpl");
  
  $smarty->display("footer.tpl");
?>

    
    
